package org.sy.lab.Java7并发编程实战.八测试并发应用程序.五输出高效的日志;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MyLogger {
	private static Handler handler;
	public static Logger getLogger(String name) {
		Logger logger = Logger.getLogger(name);
		logger.setLevel(Level.ALL);
		try {
			if(handler == null) {
				handler = new FileHandler("recipe8.log");
				Formatter format = new MyFormatter();
				handler.setFormatter(format);
			}
			if(logger.getHandlers().length == 0) {
				logger.addHandler(handler);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return logger;
	}
}
